<?php
if (!isset($modoBusqueda) || !$modoBusqueda){
    $contextMenu[0]["link"]      = "javascript:fn_ArNuevo()";
    $contextMenu[0]["linkIcon"]  = "application_add.png";
    $contextMenu[0]["linkTitle"] = "Nuevo articulo";
}

$codigoBusqueda = "";
$nombreBusqueda = "";

if (array_key_exists('codigo', $_POST)) {
	$codigoBusqueda = $_POST["codigo"];
}elseif (array_key_exists('codigoBusqueda', $_POST)) {
	$codigoBusqueda = $_POST["codigoBusqueda"];
}

if (array_key_exists('nombre', $_POST)) {
	$nombreBusqueda = $_POST["nombre"];
}elseif (array_key_exists('nombreBusqueda', $_POST)) {
	$nombreBusqueda = $_POST["nombreBusqueda"];
}

?>
<script>
    
fn_ArGuardar = function(){
        var str=$("#frmArticulo").serialize();
        $.ajax({
                url:'/gourmet-express/trunk/src/index.php?do=Articulo&accion=registrarArticulo',
                data:str,
                type:'get',
                dataType: "json",
                success:function (data){
                    //alert(data.articuloId);                     
                    if(data.rpta=='true')
                    {
                        alert("Articulo " + data.articuloId + " registrado"); 
                        fn_ArEditar(data.articuloId);
                    }else{
                        alert(data.msgError);
                    }                      
                }
        });
};	

fn_ArDelete = function(articulo){
        
        var str=$("#frmArticulo").serialize();
        $.ajax({
                url:'/gourmet-express/trunk/src/index.php?do=Articulo&accion=eliminarArticulo&articuloId='+articulo,
                data:str,
                type:'get',
                dataType: "json",
                success:function (data){
                    alert('success'+data.articuloId);                     
                    if(data.rpta=='true')
                    {
                        alert("Articulo " + data.articuloId + " eliminado"); 
                        fn_ArEditar(data.articuloId);
                    }else{
                        alert(data.msgError);
                    }                      
                }
        });
};


fn_ArNuevo = function(){
        $("#zonaContenedor").load("/gourmet-express/trunk/src/index.php?do=Articulo&accion=shwForm", function(){

        });
}; 

		
 fn_ArEditar = function(articuloId){			
		   $("#zonaContenedor").load("/gourmet-express/trunk/src/index.php?do=Articulo&accion=shwForm&articuloId="+articuloId, function(){
		   	
		   });
 }
	
 fn_ArDetalle = function (articuloId){			
		   $("#zonaContenedor").load("/gourmet-express/trunk/src/index.php?do=Articulo&accion=shw&articuloId="+articuloId, function(){
		   	
		   });
 }

 
 fn_ArDetalleOld = function (recetaId){
				$("#div_oculto").load("/gourmet-express/trunk/src/views/produccion/recetas/detalle.php?txtRecetaId="+recetaId, function(){
					$.blockUI({
						message: $('#div_oculto'),
						css:{
							top: '20%'
						}
					}); 
				});
			};
			
fn_ArEliminar =  function (pro_eli,tr_id){
  };
		
 fn_ArCerrar = function (){
	      
         };
  
</script>
<body>

<div id="main">
  <?php include $_SERVER['DOCUMENT_ROOT'].'/gourmet-express/trunk/src/views/header.inc'; ?>
  <div id="zonaContenedor">
    <h3>.:: Articulos </h3>
    <div>

	<form id='formItem' name='formItem' method="post" >    
         <table>
             <tr>
                 <td>
                    Codigo : <input type="text" name="articuloId" size="15" value="<?php echo $codigoBusqueda?>">
                 </td>   
                 <td>
                    Descripcion : <input type="text" name="descripcion" size="25" value="<?php echo $nombreBusqueda?>">  
                 </td>
                 <td>
                    Tipo : 
                     <select name="tipoArticulo" id="tipoArticulo">
                          <option></option>
                     <?php 
                               foreach ($a_tipoArticulo as $valor) {
                                    ?>
                                    <option <?php if ($valor->getValorId() == $tipoArticulo){echo "SELECTED";}?> value="<?php echo $valor->getValorId()?>"><?php echo $valor->getDescripcion()?></option>
                                    <?php
                               }
                          ?>		    
                     </select>                     
                </td>
                <td>
                    <input type="submit" name="aceptar" value="aceptar" >    
                </td>
             </tr>
         </table>
	</form>         
		
		<table id="flex1" style="display:none"></table>
		<script type="text/javascript">
		$("#flex1").flexigrid({
			url: '/gourmet-express/trunk/src/index.php?do=Articulo&accion=listarArticulo',
			dataType: 'json',
			colModel : [
				{display: 'Articulo', name : 'articuloId', width : 100, sortable : true, align: 'left'},
				{display: 'Descripcion', name : 'descripcion', width : 200, sortable : true, align: 'left'},
				{display: 'Tipo', name : 'tipoId', width : 60, sortable : true, align: 'left'},
				{display: 'Cod Fabricante', name : 'codFabricante', width : 80, sortable : true, align: 'left'},
				{display: '&nbsp;', name : 'opciones', width : 80, sortable : true, align: 'right'}
				],
			searchitems : [
				{display: 'Articulo', name : 'articuloId'},
				{display: 'Marca', name : 'marcaId', isdefault: true}
				],
			sortname: "receta_Id",
			sortorder: "asc",
			usepager: true,
			title: 'Articulos',
			useRp: true,
			rp: 15,
			showTableToggleBtn: true,
			width: 800,
			onSubmit: addFormData,
			height: 270
		});   
		
		
		//This function adds paramaters to the post of flexigrid. You can add a verification as well by return to false if you don't want flexigrid to submit			
		function addFormData(){
			//passing a form object to serializeArray will get the valid data from all the objects, but, if the you pass a non-form object, you have to specify the input elements that the data will come from
			var dt = $('#formItem').serializeArray();
			$("#flex1").flexOptions({params: dt});
			return true;
		}
			
		$('#formItem').submit(function (){
			$('#flex1').flexOptions({newp: 1}).flexReload();
			return false;
		});
		</script>
	</div>
    </div>
	<div id="div_listar" align="center"></div>
	<div id="div_oculto" style="display: none;"></div>
</body>
<script>
//fn_buscar();
</script>